<template>
  <div>
    <!-- 内容展示区域 -->
    <div class="back" @click="changefather('defaultcom')">&lt;&lt;基本信息</div>
    <ul class="card-ul">
      <li v-for="(item,index) in menuListCopy" :key="index" @click="goMenu(item.menuId)">
        <div class="card-img" :style="{ 'backgroundImage': 'url(/api/upload/'+item.menuBigImg+')'}"></div>
        <div class="card-footer">
          <div>{{item.menuName}}</div>
          <div>{{item.menuTime|timerFilter('-')}}</div>
        </div>
      </li>
    </ul>

    <!-- 分页 -->
    <div class="page">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="8"
        :total="totalNum"
        @current-change="handleCurrentChange"
        @prev-click="handleCurrentChange"
        @next-click="handleCurrentChange"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import "@/assets/style/global.css";
import "@/styles/myElPagination.scss";
export default {
  name: "MyMenu",
  mounted() {
    this.loadData();
  },
  data() {
    return {
      menuList: {},
      showData: false,
      totalNum: 0,
      menuListCopy: []
    };
  },
  methods: {
    loadData() {
      this.$axios
        .get("/api/users/getMyMenus")
        .then(res => {
          this.menuList = res.data.results;
          this.menuListCopy =
            this.menuList.length > 8
              ? this.menuList.slice(0, 8)
              : this.menuList;
          this.totalNum = this.menuList.length;
        })
        .catch(err => {
          console.log("err", err);
        });
    },
    changefather(p1) {
      this.$parent.changesoncom(p1);
    },
    goMenu(id) {
      this.$router.push({ path: `/menuchild/${id}` });
    },
    handleCurrentChange(currentPage) {
      this.menuListCopy = this.menuList.slice(
        (currentPage - 1) * 8,
        this.totalNum - 8 * (currentPage - 1) >= 8
          ? currentPage * 8
          : this.totalNum
      );
    }
  }
};
</script>
<style lang="scss" scoped>
.back {
  width: 100%;
  height: 40px;
  line-height: 40px;
  color: #e6a23c;
  margin-bottom: 15px;
}
.back:hover {
  color: #e6a23c;
  opacity: 0.8;
}
.card-ul {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  li {
    width: 200px;
    margin-right: 20px;
    border-radius: 10px;
    transition: all 0.6s;
    margin-bottom: 20px;
    box-shadow: 0 0 10px #ccc;
    .card-img {
      width: 100%;
      height: 200px;
      border-radius: 10px;
      transition: all 0.6s;
      background-size: cover;
    }
    .card-footer {
      width: 100%;
      border-radius: 10px;
      line-height: 2;
      display: flex;
      flex-direction: column;
      align-items: center;
      background-color: #fff;
      border: none;
      transition: all 0.6s;
      div:nth-child(1) {
        width: 160px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        text-align: center;
      }
    }
  }
  li:nth-child(4n) {
    margin-right: 0;
  }
  li:hover {
    cursor: pointer;
    .card-img {
      transform: scale(1.1, 1.1);
    }
    .card-footer {
      color: #e6a23c;
    }
  }
}
</style>